package com.tenglong.loginIntercept;

import com.tenglong.user.pojo.User;
import com.tenglong.user.service.UserService;
import com.tenglong.util.Constant;
import com.tenglong.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class NewFactory {
    @Autowired
    private UserService userService;

        @RequestMapping("/admin")
        public String  admin(HttpServletRequest request, HttpServletResponse response, Model model,@RequestParam(value = "pageNum",defaultValue = "1") int page) throws ServletException, IOException {

            String cartNo=request.getParameter("cartNo");
            int pageNum= page;
            int pageSize = Constant.DEFAULT_PAGE_SIZE;
            //调用service 获取查询结果
            Pager<User> result = userService.findStudent(cartNo,
                    pageNum, pageSize);

            // 返回结果到页面
            model.addAttribute("result", result);
            if(cartNo==null){
                model.addAttribute("cartNo","");
            }else {
                model.addAttribute("cartNo", cartNo);
            }
            return "right";
    }
}
